package ui.tree.renderer.suggest
{
	import flash.display.Graphics;
	import flash.events.Event;
	
	import mx.controls.CheckBox;

	public class CheckBoxRenderer extends CheckBox {
		public function CheckBoxRenderer(){
			super();
			this.height = 22;
			// => Add listener to detect change in selected
			this.addEventListener(Event.CHANGE, onChangeHandler);
		}
		
		// Override the set method for the data property.
		override public function set data(value:Object):void {
			super.data = value;
			
			// => Make sure there is data
			if (value != null) {
				// => Set the label
				this.label = value.label;
				
				// => Set the selected property
				this.selected = value.selected;
			}
			changeStyle();
			// => Invalidate display list,
			// => If checkbox is now selected, we need to redraw
			super.invalidateDisplayList();
		}
		
		// => Handle selection change
		private function onChangeHandler(event:Event):void {
			super.data.selected = !super.data.selected;
			changeStyle();
		}
		
		private function changeStyle():void{
			if(this.selected){
				this.setStyle("color",0X0000ff);
			}else{
				this.setStyle("color",0X000000);
			}
		}
	}
}